package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/11 00:07
 **/
public class Day8_8_Num283_MoveZeroes {
    class Solution {
        public void moveZeroes(int[] nums) {
            int len = nums.length;
            for(int i = 0; i < len;){
                if(nums[i] == 0 && i != len-1){
                    int cur = nums[i];
                    for(int j = i; j < nums.length-1; ++j){
                        nums[j] = nums[j+1];
                    }
                    nums[nums.length-1] = cur;
                    len--;
                }else i++;
            }
            return;
        }
    }
    class Solution2 {
        public void moveZeroes(int[] nums) {
            if(nums.length == 0) return;
            int index = 0, n = nums.length;
            for(int i = 0; i < n; ++i){
                if(nums[i] != 0){
                    nums[index] = nums[i];
                    index++;
                }
            }
            for(int i = index; i < n; ++i){
                nums[i] = 0;
            }
            return;
        }
    }
}